package android.demo.engine.tasks;

import java.util.ArrayList;
import java.util.List;

import android.demo.engine.ProcessStateManager;
import android.demo.engine.visitor.TaskVisitor;

/**
 * @author  carlo
 */
public abstract class Task {
		/**
		 * @uml.property  name="id"
		 */
		private int id;
		
		private boolean executed;
		
		private List<ServiceTask> servicesToBeCompleted;
		
		
		public Task(int id) {
			super();
			this.id = id;
			init();
		}
		public void init(){
			this.executed=false;
		};

		public abstract void accept(TaskVisitor visitor);
		
		public abstract short getType();
		
		/**
		 * @return
		 * @uml.property  name="id"
		 */
		public int getId() {
			return id;
		}
		
		public Task hasToWait() {
			if(servicesToBeCompleted!=null)
				for(ServiceTask st : servicesToBeCompleted)
					if(!st.isExecuted())
						return st;
			return null;
		}
		public void addServiceToBeCompleted(ServiceTask st){
			if(servicesToBeCompleted==null)
				servicesToBeCompleted= new ArrayList<ServiceTask>();
			servicesToBeCompleted.add(st);
		}

		public static class Types{
			public static final short ACTIVITY_TASK =0;
			public static final short SERVICE_BINDER_TASK =1;
			public static final short SERVICE_STARTER_TASK =2;
			public static final short CONTENT_PROVIDER_TASK =3;
		}

		public boolean isExecuted() {
			return executed;
		}
		public void finish() {
			this.executed=true;
		}



}
